#!/bin/sh

[ ${ACTION} = "remove" -a -n "${DEVICENAME}" ] && {
	kill $(cat /var/run/hostapd-${DEVICENAME}.pid)
	rm -rf /var/run/hostapd-${DEVICENAME}.pid /var/run/hostapd-${DEVICENAME}/
	kill $(cat /var/run/wpa_supplicant-${DEVICENAME}.pid)
	rm -rf /var/run/wpa_supplicant-${DEVICENAME}.pid /var/run/wpa_supplicant-${DEVICENAME}/
}

[ ${ACTION} = "add" -a -n "${DEVICENAME}" ] && {
	/usr/sbin/hostapd -s -n ${DEVICENAME} -P /var/run/hostapd-${DEVICENAME}.pid -g /var/run/hostapd-${DEVICENAME}/global -B &
	mkdir -p /var/run/wpa_supplicant-${DEVICENAME}
	/usr/sbin/wpa_supplicant -s -n ${DEVICENAME} -P /var/run/wpa_supplicant-${DEVICENAME}.pid -g /var/run/wpa_supplicant-${DEVICENAME}/global -B &
}
